package com.yunban.project.template.controller;

import com.yunban.project.template.model.dto.TemplateReq;
import com.yunban.project.template.model.dto.TemplateSearchReq;
import com.yunban.project.template.model.vo.TemplateResp;
import com.yunban.project.template.service.TemplateCollectService;
import com.yunban.project.template.service.TemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: lijiajun
 * @date: 2024-11-06
 * @version: 1.0
 */
@OperateLog
@RestController
@Tag(name = "模板模块")
@RequestMapping("/template-api")
public class TemplateController {

    @Resource
    private TemplateService templateService;

    @GetMapping("/list")
    @Operation(summary = "获取模板列表-全量")
    List<TemplateResp> list() {
        return templateService.getTemplateList();
    }

    @PostMapping("/search")
    @Operation(summary = "获取模板列表")
    PageResult<TemplateResp> search(@RequestBody TemplateSearchReq req) {
        return this.templateService.search(req);
    }

    @PostMapping
    @Operation(summary = "添加模板")
    Boolean saveTemplate(@RequestBody @Validated TemplateReq req) {
        return templateService.saveTemplate(req);
    }

    @PutMapping("/{id}")
    @Operation(summary = "修改模板")
    Boolean editTemplate(@PathVariable long id, @RequestBody @Validated TemplateReq req) {
        return templateService.editTemplate(id, req);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除模板")
    Boolean delTemplate(@PathVariable long id) {
        return templateService.delTemplate(id);
    }
}
